package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dto.ChannelDto;
import com.heima.model.admin.pojo.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.validator.ValidatorAdd;
import com.heima.model.common.validator.ValidatorUpdate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** @author 可爱迷人的菜菜 */
@Api(value = "频道管理", tags = "频道管理API")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {
  @Autowired
  private AdChannelService adChannelService;

  @ApiOperation("频道分页列表查询")
  @PostMapping("/list")
  public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
    return adChannelService.findByNameAndPage(dto);
  }
  @ApiOperation("查询全部频道")
  @GetMapping("/channels")
  public ResponseResult findAll() {
    List<AdChannel> list = adChannelService.list();
    return ResponseResult.okResult(list);
  }



  @ApiOperation("频道新增")
  @PostMapping("/save")
  public ResponseResult insert(@RequestBody @Validated(ValidatorAdd.class) AdChannel adChannel) {
    return adChannelService.insert(adChannel);
  }
  @ApiOperation("频道修改")
  @PostMapping("/update")
  public ResponseResult update(@RequestBody @Validated(ValidatorUpdate.class) AdChannel adChannel) {
    return adChannelService.amend(adChannel);
  }
  @ApiOperation("频道删除")
  @GetMapping("/del/{id}")
  public ResponseResult delete(@PathVariable("id") Integer id) {
    return adChannelService.deleteById(id);
  }


}
